package com.yq.socket1.day1.practice.test3;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author 3307235355@qq.com
 * @description 客户端文本文件，服务器输出文本文件
 * @since 2022/07/01 14:23
 */
public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8888);

        Socket socket = serverSocket.accept();

        InputStream inputStream = socket.getInputStream();
        FileOutputStream outputStream = new FileOutputStream("copy_a.txt");

        byte[] bytes = new byte[1024];
        int read;
        while ((read=inputStream.read(bytes))!=-1){
            outputStream.write(bytes,0,read);
        }
        System.out.println("打印完成！");

        outputStream.close();

        socket.close();
        serverSocket.close();
    }
}
